<?php 		
#Agregar Preferencias
#Agregar ir a puerto

#----------Pegado de datos
$mysqluser = addslashes($_POST['mysqluser']);
$mysqlpass = addslashes($_POST['mysqlpass']);
$myhost = addslashes($_POST['myhost']);
$chequearphp = addslashes($_POST['checkphp']);
$chequearsql = addslashes($_POST['checksql']);
$chequearport = addslashes($_POST['checkport']);
$chequeartraf = addslashes($_POST['checkes']);
#----------Funciones PHP y JS
if ($_SERVER[HTTP_REFERER] == "http://localhost/index.php" || ($_SERVER[HTTP_REFERER] == "http://localhost/NND/")) {
	session_start();
	$_SESSION[CAM] = true;
	} else {
	header('Location: index.php');
}

	function aprobado() {
		echo "<td align=\"center\"><img src=\"./Resources/greenlight.tiff\" title=\"This configuration seems correct. You shouldn't modify it\"/></td>";		
	}
	function desaprobado() {
		echo "<td align=\"center\"><img src=\"./Resources/redlight.tiff\" title=\"Beware, this configuration can lead to security issues and/or a serious harm. You should correct it.\"/></td>";		

	}
	function advertencia() {
		echo "<td align=\"center\"><img src=\"./Resources/orangelight.tiff\" title=\"This configuration MAY cause issues, by itself or in conjunction with another misconfiguration.\"/></td>";
		
	}
	function bot() {
		echo "<td align=\"center\"><input type=\"button\" value=\"?\" onclick=\"";
	}
	function on(){
		echo "\" /></td></tr><tr>";
	}
	function bot2() {
		echo "<form action=\"Mapper.php\" method=\"post\"><input type=\"hidden\" name=\"irapuerto\" id=\"irapuerto\" value=\"";
	}
	function on2(){
		echo "\" /></td>";
	}
	function on3() {
		echo "\" /><td align=\"center\"><input type=\"submit\" value=\"->\" /></form></td></tr><tr>";
		
	}
#----------Cabecera + Stylesheet + Scripts JS
	echo "<head><title>NND</title><link type=\"text/css\" rel=\"stylesheet\" href=\"./Resources/NND.css\" />
	
	<script>
	function register_globals(){ alert('Registers variables as globals. This may lead to variable manipulation by the user.');}
		function magic_quotes_gpc(){ alert('Magic quotes can be useful when you forget to add slashes or to sanitize some input. You shouldn\'t rely on this feature and stop sanitizing content yourself.');}
			function safe_mode(){ alert('PHP Safe mode serves as a restrictive PHP environment. Can be safely left aside.');}
				function allow_url_include(){ alert('Allows including remote files into the script. You shouldn\'t rely on this feature unless you are taking information from another external site and fetching it on your script.');}
					function display_errors(){ alert('Shows PHP generated errors, including the script name and location.');}
						function expose_php(){ alert('Tells the server signature to expose the fact that PHP is installed.');}


	
	function have_openssl(){ alert('OpenSSL allows you to establish secure communications from end to end.');}
	function have_ssl(){ alert('SSL allows you to establish secure communications from end to end.');}
	function have_crypt(){ alert('Enables crypt.');}
	function secure_auth(){ alert('Enables secure authentication.');}
	function ssl_cipher(){ alert('Enables cipher.');}
	function error_count(){ alert('How many errors the server has processed.');}
	function warning_count(){ alert('How many warnings the server has processed.');}
	function port(){ alert('Default MySQL port. If you can, change it, so automatic established attack vectors would fail on seeking a MySQL port.');}
				
			
			
				function p21() { alert('File Transfer Protocol. If you haven\'t installed an FTP server, you should check this.'); }
							function p23() { alert('Telnet port. If you aren\'t expecting to use it, just close it.'); }
				function p80() { alert('Webserver port.'); }
		
function p81() { alert('Mostly used by webservers like Nginx and LightTPD.'); }
		function p25() { alert('Mail Server port. If you\'re not running a mail server, you have to check this, as you may be infected or enslaved to a botnet.'); }
			function p3306() { alert('MySQL port.'); }
				function p22() { alert('SSH port. If you\'re not running an SSH yourself, you may be victim of an intrusion.'); }
					function p53() { alert('DNS port.'); }
						
						function p107() { alert('Remote Telnet Service. If you\'re not sending/receiving remote data via telnet, you may be victim of an intrusion.'); }
						function p118() { alert('SQL port.'); }
						function p156() { alert('SQL Services port.'); }
					function p514() { alert('Remote Shell Services port. If you\'re not using this, you may be an intrusion victim.'); }
										
				function p992() { alert('Telnet over TSL/SSL. If you\'re not running this, you may be an intrusion victim.'); }	
	function p194() { alert('IRC port. If you\'re not running this, you may be an intrusion victim, or your machine could got enslaved by a botnet.'); }


	</script>
	</head>";
#----------Prueba de Conexion
echo "<tt> <b> <u>CONNECTION</u> </b> </tt><BR>";
echo "<tt> <b> User: </b> $mysqluser </tt><BR>";
@mysql_connect("$myhost", "$mysqluser", "$mysqlpass")
or die("<tt><b><font color=\"red\">Unable to connect to the server.</b></font></tt>");
@mysql_select_db("information_schema")
or die("<tt><b><font color=\"red\">Unable to establish a database connection.</b></font></tt>");
echo "<tt><b> Status: <font color=\"green\">OK</font></b></tt><BR>";
$consultaenv = "SELECT VARIABLE_VALUE FROM GLOBAL_STATUS WHERE VARIABLE_NAME='BYTES_SENT'";
$env = mysql_query($consultaenv);
while ($row = mysql_fetch_array($env)) {
	$consultaenv = $row[VARIABLE_VALUE];
}
$consultarec = "SELECT VARIABLE_VALUE FROM GLOBAL_STATUS WHERE VARIABLE_NAME='BYTES_RECEIVED'";
$rec = mysql_query($consultarec);
while ($row = mysql_fetch_array($rec)) {
	$consultarec = $row[VARIABLE_VALUE];
}
if ($chequeartraf == "Trafico") {
echo "<tt><b> Traffic sent: </b>$consultaenv Bytes</tt><BR>";
echo "<tt><b> Traffic received: </b>$consultarec Bytes</tt><BR>";
}
#----------Prueba PHP
if ($chequearphp == "PHP") {
echo "<BR><tt> <b><u>PHP</u></b></tt><BR><BR>";
 echo "<table border=\"1\" cellpadding=\"1\" cellspacing=\"2\"><th><tt>VARIABLE</tt></th><th><tt>VALUE</tt></th><th><tt>ESTADO</tt></th><th><tt>&nbsp;EXPLAIN</tt></th>";
echo "<tr><td><tt> <b> register_globals: </b></tt></td>"; if (ini_get('register_globals') == "" || (ini_get('register_globals')) == "Off") { echo "<td><tt>Disabled </tt></td>"; echo aprobado(); } else { echo "<td><tt>Enabled </tt></td>"; echo desaprobado(); } echo bot(); echo "register_globals()"; echo on();
echo "<td><tt> <b> magic_quotes_gpc: </b></tt></td>"; if (ini_get('magic_quotes_gpc') == "" || (ini_get('magic_quotes_gpc')) == "Off") { echo "<td><tt>Disabled </tt></td>"; echo desaprobado(); } else { echo "<td><tt>Enabled </tt></td>"; echo aprobado(); } echo bot(); echo "magic_quotes_gpc()"; echo on();
echo "<td><tt> <b> safe_mode: </b></tt></td>"; if (ini_get('safe_mode') == "" || (ini_get('safe_mode')) == "Off") { echo "<td><tt>Disabled </tt></td>"; echo advertencia(); } else { echo "<td><tt>Enabled </tt></td>"; echo aprobado();} echo bot(); echo "safe_mode()"; echo on();
echo "<td><tt> <b> allow_url_include: </b></tt></td>"; if (ini_get('allow_url_include') == "" || (ini_get('allow_url_include')) == "Off") { echo "<td><tt>Disabled </tt></td>"; echo aprobado(); } else { echo "<td><tt>Enabled </tt></td>"; echo advertencia(); } echo bot(); echo "allow_url_include()"; echo on();
echo "<td><tt> <b> display_errors: </b></tt></td>"; if (ini_get('display_errors') == "" || (ini_get('display_errors')) == "Off") { echo "<td><tt>Disabled </tt></td>"; echo aprobado(); } else { echo "<td><tt>Enabled </tt></td>"; echo desaprobado();} echo bot(); echo "display_errors()"; echo on();
echo "<td><tt> <b> expose_php: </b></tt></td>"; if (ini_get('expose_php') == "" || (ini_get('expose_php')) == "Off") { echo "<td><tt>Disabled </tt></td>"; echo aprobado(); } else { echo "<td><tt>Enabled </tt></td>"; echo advertencia();} echo bot(); echo "expose_php()"; echo on();
echo "</tr></table>";
}
#----------Prueba MySQL
if ($chequearsql == "MySQL") {
echo "<BR><tt> <b><u>MySQL</u></b></tt><BR><BR>";
echo "<table border=\"1\" cellpadding=\"1\" cellspacing=\"2\"><th><tt>VARIABLE</tt></th><th><tt>VALUE</tt></th><th><tt>ESTADO</tt></th><th><tt>&nbsp;EXPLAIN</tt></th>";
$check = "SELECT VARIABLE_VALUE FROM SESSION_VARIABLES WHERE VARIABLE_NAME='HAVE_OPENSSL'";
$resultado = mysql_query($check); 
while ($row = mysql_fetch_array($resultado)) {
        $check = $row[VARIABLE_VALUE];
        }
echo "<tr><td><tt> <b> HAVE_OPENSSL: </b></tt></td>"; if ($check == "NO") { echo "<td><tt>Disabled </tt></td>"; echo advertencia(); } else { echo "<td><tt>Enabled </tt></td>"; echo aprobado();} echo bot(); echo "have_openssl()"; echo on();
$check = "SELECT VARIABLE_VALUE FROM SESSION_VARIABLES WHERE VARIABLE_NAME='HAVE_SSL'";
$resultado = mysql_query($check); 
while ($row = mysql_fetch_array($resultado)) {
        $check = $row[VARIABLE_VALUE];
        }
echo "<td><tt> <b> HAVE_SSL: </b></tt></td>"; if ($check == "NO") { echo "<td><tt>Disabled </tt></td>"; echo advertencia(); } else { echo "<td><tt>Enabled </tt></td>"; echo aprobado();} echo bot(); echo "have_ssl()"; echo on();

$check = "SELECT VARIABLE_VALUE FROM SESSION_VARIABLES WHERE VARIABLE_NAME='HAVE_CRYPT'";
$resultado = mysql_query($check); 
while ($row = mysql_fetch_array($resultado)) {
        $check = $row[VARIABLE_VALUE];
        }
echo "<td><tt> <b> HAVE_CRYPT: </b></tt></td>"; if ($check == "NO" || $check == "") { echo "<td><tt>Disabled </tt></td>"; echo desaprobado(); } else { echo "<td><tt>Enabled </tt></td>"; echo aprobado();} echo bot(); echo "have_crypt()"; echo on();

$check = "SELECT VARIABLE_VALUE FROM SESSION_VARIABLES WHERE VARIABLE_NAME='SECURE_AUTH'";
$resultado = mysql_query($check); 
while ($row = mysql_fetch_array($resultado)) {
        $check = $row[VARIABLE_VALUE];
        }
echo "<td><tt> <b> SECURE_AUTH: </b></tt></td>"; if ($check == "NO") { echo "<td><tt>Disabled </tt></td>"; echo advertencia(); } else { echo "<td><tt>Enabled </tt></td>"; echo aprobado();} echo bot(); echo "secure_auth()"; echo on();

$check = "SELECT VARIABLE_VALUE FROM GLOBAL_VARIABLES WHERE VARIABLE_NAME='SSL_CIPHER'";
$resultado = mysql_query($check); 
while ($row = mysql_fetch_array($resultado)) {
        $check = $row[VARIABLE_VALUE];
        }
echo "<td><tt> <b> SSL_CIPHER: </b></tt></td>"; if ($check == "NO" || $check == "") { echo "<td><tt>Disabled </tt></td>"; echo advertencia(); } else { echo "<td><tt>Enabled </tt></td>"; echo aprobado();} echo bot(); echo "ssl_cipher()"; echo on();


$check = "SELECT VARIABLE_VALUE FROM GLOBAL_VARIABLES WHERE VARIABLE_NAME='ERROR_COUNT'";
$resultado = mysql_query($check); 
while ($row = mysql_fetch_array($resultado)) {
        $check = $row[VARIABLE_VALUE];
        }
echo "<td><tt> <b> ERROR_COUNT: </b></tt></td>"; if ($check != "0") { echo "<td><tt>True </tt></td>"; echo advertencia(); } else { echo "<td><tt>False </tt></td>"; echo aprobado();} echo bot(); echo "error_count()"; echo on();

$check = "SELECT VARIABLE_VALUE FROM GLOBAL_VARIABLES WHERE VARIABLE_NAME='WARNING_COUNT'";
$resultado = mysql_query($check); 
while ($row = mysql_fetch_array($resultado)) {
        $check = $row[VARIABLE_VALUE];
        }
echo "<td><tt> <b> WARNING_COUNT: </b></tt></td>"; if ($check != "0") { echo "<td><tt>True </tt></td>"; echo advertencia(); } else { echo "<td><tt>False </tt></td>"; echo aprobado();} echo bot(); echo "warning_count()"; echo on();


$check = "SELECT VARIABLE_VALUE FROM SESSION_VARIABLES WHERE VARIABLE_NAME='PORT'";
$resultado = mysql_query($check); 
while ($row = mysql_fetch_array($resultado)) {
        $check = $row[VARIABLE_VALUE];
        }
echo "<td><tt> <b> PORT: </b></tt></td>"; if ($check == "3306") { echo "<td><tt>Default ($check)</tt></td>"; echo advertencia(); } else { echo "<td><tt>Custom ($check)</tt></td>"; echo aprobado();} echo bot(); echo "port()"; echo on();

echo "</tr></table>";
}
#----------Footer
echo "<BR><form id=\"footer\" name=\"footer\"><tt><img src=\"./Resources/Lock.tiff\" width=\"24\" height=\"24\" title=\"Invest in security.\"/> Copyright 2012 - Mauro Eldritch (Mauro F Caseres) - <a href=\"www.eldritch.com.ar\"> Eldritch Software.</a></tt>
<BR><tt><img src=\"./Resources/Finder.tiff\" width=\"24\" height=\"24\" title=\"Mac OS X 10.4.11 TIGER\"/> Built with Mac OS X 10.4 TIGER - <a href=\"www.apple.com\"> Apple.</a></tt>
</form>";

#----------Scanner
if ($chequearport == "Puertos") {
echo "<form id=\"scanner\" name=\"scanner\"/>";
ini_set("max_execution_time",120);

$rangeStart = 0;
$rangeStop = 1024;
$target = $myhost;
$range =range($rangeStart, $rangeStop);
echo "<table border=\"1\" cellpadding=\"1\" cellspacing=\"2\"><th><tt>PORT</tt></th><th><tt>STATUS</tt></th><th><tt>EXPLAIN</tt></th><th><tt>GO TO</tt></th><tr>";

foreach ($range as $port) {
    $result = @fsockopen($target, $port, $errno, $errstr, 1);
    if ($result) echo "<td><tt>$port</tt></td>";
		if($result && $port == "21" || $result && $port == "25" || $result && $port == "81") { echo advertencia(); echo bot(); echo "p$port()"; echo on2(); echo bot2(); echo "$port"; echo on3();} elseif ($result && $port == "23" || $result && $port == "3306" || $result && $port == "22" || $result && $port == "53" || $result && $port == "107" || $result && $port == "118" || $result && $port == "156" || $result && $port == "311" || $result && $port == "514" || $result && $port == "194" || $result && $port == "992") { echo desaprobado(); echo bot(); echo "p$port()"; echo on2(); echo bot2(); echo "$port"; echo on3(); } elseif ($result && $port != "") { echo aprobado(); echo bot(); echo "p$port()"; echo on2(); echo bot2(); echo "$port"; echo on3();}
    }
echo "</form>";
}

										#NUEVO LOGRO DESBLOQUEADO
			#Cartonero.php : Reciclar mas de cien lineas de php! efectividad de trabajo +100%
?>